package com.vehiclesecure.config;

import com.vehiclesecure.security.JwtAuthenticationFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
 * 专门用于注册JWT认证过滤器的配置类
 */
@Configuration
public class JwtFilterConfig {
    
    /**
     * 注册JWT过滤器为Spring Bean，确保它被正确加载
     */
    @Bean
    public FilterRegistrationBean<JwtAuthenticationFilter> registerJwtFilter(@Lazy JwtAuthenticationFilter filter) {
        FilterRegistrationBean<JwtAuthenticationFilter> registrationBean = new FilterRegistrationBean<>(filter);
        registrationBean.setEnabled(false); // 禁用自动注册，因为我们已经通过SecurityConfig中的SecurityFilterChain手动注册了
        return registrationBean;
    }
}